/*复用逻辑的函数*/

/*
* 数据懒加载函数
* dom是要监听的dom,Fn是dom进入可视区后执行的函数
* */
import {useIntersectionObserver} from "@vueuse/core";
import {ref} from "vue";

export const lazyLoading=(dom, apiFn)=>{
    const data=ref([])
    const { stop } = useIntersectionObserver(
        dom,
        ([{ isIntersecting }], observerElement) => {
        if (isIntersecting){
            stop()
            apiFn().then(({result})=>{
            data.value=result
            })
        }
        },
    )
    return data
}